<@pp.dropOutputFile />
<#import "../lib/lib.ftl" as lib/>
<#list dalgen.tables as table>
<@pp.changeOutputFile name = "/${dalgen.tablesPath}/${table.sqlName}.xml" />
<!DOCTYPE table SYSTEM "../config/table-config-1.0.dtd">
<table sqlname="${table.sqlName}" physicalName="${table.physicalName}"<#if table.remark??> remark="${table.remark!}"</#if>>
    <!--  特殊字符说明  &lt;&gt;   <> -->

    <operation name="insert" paramtype="object" remark="插入表:${table.sqlName}">
        <#if dalgen.dbType=="MySQL">
        <selectKey resultType="java.lang.Long" keyProperty="id" order="AFTER">
            SELECT
            LAST_INSERT_ID()
        </selectKey>
        </#if>
        INSERT INTO ${table.sqlName}(
        	<include refid="Base_Column_List" />
        )VALUES(
        <#list table.columnList as column>
            <#if column_index gt 0>,</#if> ${lib.insertVal(column)}
        </#list> 
        )
    </operation> 
    
    <operation name="deleteById" paramtype="primitive">
        UPDATE ${table.sqlName}
        SET DELETE_FLAG = 0 ,UPDATED_DATE = NOW()
        WHERE ID = ${"#"}{id} AND DELETE_FLAG= 0
    </operation>

	<!-- 要更新成null值，请在业务层做 针对每个对象 设置某个默认值 则是将该字段设置为空 -->
    <operation name="updateById" paramtype="object">
        UPDATE ${table.sqlName}
        SET UPDATED_DATE = NOW()
        <#list table.columnList as column>
	    	<#if lib.updateIncludeColumn(column,table.primaryKeys.columnList) >
		    	<if test="${column.javaName} != null">
		        	,${column.sqlName} = ${lib.updateVal(column)}
		        </if>
	        </#if>
	    </#list>
        WHERE ID = ${"#"}{id}  AND DELETE_FLAG = 0
    </operation>

    <operation name="queryById" multiplicity="one" paramtype="primitive" >
        SELECT *
        FROM ${table.sqlName}
        WHERE ID = ${"#"}{id} AND DELETE_FLAG = 0 
    </operation>
    
    <operation name="queryByModel" multiplicity="many" paramtype="object">
        SELECT *
        FROM ${table.sqlName}
        <trim prefix="where" prefixOverrides="AND ">
	        <#list table.columnList as column>
	        	<#if lib.queryIncludeColumn(column,table.primaryKeys.columnList)>
		    <if test="${column.javaName} != null ">
		        AND  ${column.sqlName} = ${"#"}{${column.javaName}}
		    </if>
		        </#if>
	        </#list>
          AND DELETE_FLAG = 0
        </trim>
        order by updated_date desc 
    </operation>
    
</table>
</#list>